package wang.yangziqing.app_kotlin.net

import com.google.gson.Gson
import com.lzy.okgo.OkGo
import com.lzy.okgo.callback.StringCallback
import com.lzy.okgo.model.Response
import java.lang.reflect.Type


/**
 * Created by Administrator on 2017/12/6.
 */
object OkGoUtil {

      fun  <T> sendPost(url: String, type: Type ,listener : NetListener) {
        println("网络请求方法开始调用")

        OkGo.get<String> (url)
                .execute(object: StringCallback() {
                    override fun onSuccess(response: Response<String>?) {
                        val toString = response?.body().toString()
                        val gson = Gson()
                        val fromJson = gson.fromJson<T>(toString, type)
                        println(111111111111)
                        println(fromJson.toString())
                        listener.onSuccess<T>(fromJson)
                    }
                })

    }



}